<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class Company extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'company';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'management_text',
        'register_time_text',
        'identificationswitch_text',
    ];

    public function getIdentificationswitchList()
    {
        return ['0' => '未认证','1' => '已认证'];
    }


    public function getManagementList()
    {
        return ['1' => __('Management 1'), '0' => __('Management 0')];
    }


    public function getManagementTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['management']) ? $data['management'] : '');
        $list = $this->getManagementList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRegisterTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['register_time']) ? $data['register_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setRegisterTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function getIdentificationswitchTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['identificationswitch']) ? $data['identificationswitch'] : '');
        $list = $this->getIdentificationswitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }

}
